extends Area2D


@export var slime_speed : float = -50
@export var slime : AnimatedSprite2D
@export var deathSound : AudioStreamPlayer

var is_dead : bool = false

func _physics_process(delta: float) -> void:
	if not is_dead:
		position += Vector2(slime_speed,0) * delta
	
	if position.x < -267:
		queue_free()


func _on_body_entered(body: Node2D) -> void:
	if body is CharacterBody2D and not is_dead:
		#调用玩家自定义的重启游戏函数
		body.game_over()


func _on_area_entered(area: Area2D) -> void:
	if area.is_in_group("bullet"):
		slime.play("death")
		deathSound.play()
		is_dead = true
		area.queue_free()
		#获取主场景的score
		get_tree().current_scene.score += 1
		
		
		await get_tree().create_timer(0.6).timeout
		queue_free()
			
